<template>
  <div class="crm-page home-page">
    <div class="page-header">联系人详情</div>
    <div class="page-content transparent">
      <div class="page-card">
        <div class="card-title">
          <el-button class="back-btn" size="medium" type="text" icon="el-icon-back" @click="goMainBack()">返回</el-button>
        </div>
        <div class="page-card-content">
          <div class="item-title" style="margin-top:20px">
            基本信息
          </div>
          <div class="card-item">
            <el-row :gutter="10">
              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">姓名：</span>
                <span class="content">{{ data.name }}</span>
              </el-col>
              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">职务：</span>
                <span class="content">{{ data.position }}</span>
              </el-col>

              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">客户：</span>

                <span class="content">
                  <span class="app-link" @click="gotoMainPage('customer/info',{id:data.customerId})">  {{ data.customerName }}</span>
                </span>
              </el-col>

              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">电话：</span>
                <span class="content">{{ data.phone }}</span>
              </el-col>
              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">邮箱：</span>
                <span class="content">{{ data.email }}</span>
              </el-col>
              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">所有人：</span>
                <span class="content">{{ data.owner }}</span>
              </el-col>
            </el-row>
          </div>
        </div>
      </div>

      <el-row :gutter="20">
        <el-col :xs="24" :sm="24" :md="24" :lg="14" :xl="14">
          <div class="page-card">
            <div class="page-card-content">
              <div class="item-title">
                详细信息
              </div>
              <div class="card-item">
                <el-row :gutter="10">
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">姓名：</span>
                    <span class="content">{{ data.name }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">所有人：</span>
                    <span class="content">{{ data.owner }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">客户名：</span>
                    <span class="content">{{ data.customerName }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">客户级别：</span>
                    <span class="content">{{ data.levelText }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">职务：</span>
                    <span class="content">{{ data.position }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">邮箱：</span>
                    <span class="content">{{ data.email }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">电话：</span>
                    <span class="content">{{ data.phone }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">收货地址：</span>
                    <span class="content">
                      {{ data.addrDetail }}
                    </span>

                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">创建人：</span>
                    <span class="content">{{ data.createName }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">上次修改人：</span>
                    <span class="content">{{ data.updateName }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">创建时间：</span>
                    <span class="content">{{ formatTime(data.createTime) }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">上次修改时间：</span>
                    <span class="content">{{ formatTime(data.updateTime) }}</span>
                  </el-col>
                </el-row>
              </div>
            </div>
          </div>
          <ChanceCard v-if="data.customerId" :customer-id="data.customerId" :customer-name="data.customerName" />
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="10" :xl="10">
          <ActivityCard
            :data="{
              name:data.name,
              relateName:data.name,
              relateId:data.id
            }"
            :type="3"
            @change="handleCardChange"
          />
          <ActivityListCard v-if="data.id" ref="listCard" :relateid="data.id" :type="3" />
        </el-col>

      </el-row>

    </div>
  </div>
</template>
<script>
import ActivityCard from '@/components/ActivityCard'
import ActivityListCard from '@/components/ActivityListCard'
import ChanceCard from '@/components/InfoCard/ChanceCard'
import { getContact } from '@/api/contact'

import { getEnumText, customerLevels } from '@/utils/enums'
import { formatTime } from '@/utils/tools'

export default {
  name: 'CustomerInfo',
  components: { ChanceCard, ActivityCard, ActivityListCard },
  data() {
    return {
      data: {

      }

    }
  },
  mounted() {
    const id = this.$route.query.id
    getContact({ id }).then(res => {
      this.data = res
      if (this.data.level) {
        this.data.levelText = getEnumText(customerLevels, this.data.level)
      }
      // 地址展示判断
      if (this.data.province && this.data.city && this.data.county) {
        this.data.addrDetail = this.data.province + this.data.city + this.data.county
      }
      if (this.data.address) {
        this.data.addrDetail += this.data.address
      }
    })
  },
  methods: {
    formatTime,
    handleCardChange() {
      this.$refs.listCard.refresh()
    }

  }
}
</script>

